"""TODO header"""

import os
import urllib

from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp import template

import models


class SubmitPage(webapp.RequestHandler):
  def get(self):
    blobstore_upload_url = blobstore.create_upload_url('/do_submit')
    path = os.path.join(os.path.dirname(__file__), 'submit_page.html')
    template_values = {
      'blobstore_upload_url': blobstore_upload_url,
    }
    self.response.out.write(template.render(path, template_values))


class SubmitFormHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    submission = models.Submission()
    submission.email = self.request.get('email')
    blobstore_info = self.get_uploads('content')[0]
    submission.content_blobstore_key = '%s' % blobstore_info.key()
    submission.put()
    self.redirect('/')
